var windowName = "userNickName";
apiready = function(){
    onWindowShow(function () {
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");
    var PicUpUserHead = new PicUp()
    var Page = createVM("#Page",{
        //页面数据
        picUserHead:picUserHead,
        name:"",
        avatar:"",
        picV:""
        ,loading:0
        ,pics:[]
        ,toolsShow:false
    },{
        //页面方法
        "init":function () {
            var cache = getLocData("userInfo")
            if (isTrue(cache)) {
                this.name = cache.name
                this.avatar = cache.avatar;
                this.picV = getAssetBaseUrl() + cache.avatar
            }
            getInfo(this);
        }
        ,"submit":function() {
            var _this = this
            apiPost("/app/user/info",{avatar:this.avatar,name:this.name},function (res) {
                logJson(res)
                showToast(res.message)
                setLocData('userInfo',res.data)
            })
        },
        selectEditPic:function () {
            var _this = this;
            PicUpUserHead.selectEdit(()=>{_this.toolsShow = true})
                .setCbFunc(function (pics) {
                _this.avatar = pics[0]
                _this.picV = PicUpUserHead.getViewData(pics)[0]
            })
        }
        ,save:function () {
            PicUpUserHead.editSave()
            this.toolsShow = false
        }
        ,reset:PicUpUserHead.editReset
        ,close:function () {
            PicUpUserHead.editClose()
            this.toolsShow = false
        }
    })
    Page.init()
}


function getInfo(_this) {
    apiGet("/app/user/home",{},function (res,code) {
        logJson(res.data,"/app/user/home")
        setLocData("userInfo",res.data)
        Page.name = res.data.name;
        Page.avatar = res.data.avatar;
        Page.picV = getAssetBaseUrl() + Page.avatar
        // ProductPics.uploadedPath = [Page.avatar]
        // Page.pics = ProductPics.getViewData()
    })
}